var t = require("../../utils/config.js");

Page({
    data: {
        list: [],
        enterpriseId: "",
        enterPriseList: []
    },
    onLoad: function(t) {
        this.init();
    },
    init: function() {
        var e = this;
        wx.showLoading({
            mask: !0
        }), wx.request({
            url: t.urlList.API_USER_GET_ENTERPRISE_LIST,
            method: "GET",
            data: {
                userId: wx.getStorageSync("userId")
            },
            success: function(t) {
                if (wx.hideLoading(), 200 == t.data.status) if (t.data.data.length > 0) {
                    e.setData({
                        enterPriseList: t.data.data
                    });
                    var a = [];
                    e.data.enterPriseList.forEach(function(t, e) {
                        a.push(t.enterpriseName);
                    }), wx.showActionSheet({
                        itemList: a,
                        success: function(t) {
                            e.setData({
                                enterpriseId: e.data.enterPriseList[t.tapIndex].id
                            }), e.onPullDownRefresh();
                        }
                    });
                } else e.onPullDownRefresh(); else wx.showToast({
                    title: t.data.message,
                    icon: "none"
                });
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        this.loadDataSource();
    },
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    loadDataSource: function() {
        var e = this, a = wx.getStorageSync("serviceProviderId");
        wx.showLoading({
            mask: !0
        }), wx.request({
            url: t.urlList.API_FORM_SETTING_GET,
            method: "GET",
            data: {
                serviceProviderId: a,
                enterpriseId: e.data.enterpriseId
            },
            success: function(t) {
                wx.hideLoading(), 200 == t.data.status ? e.setData({
                    list: t.data.data
                }) : wx.showToast({
                    title: t.data.message,
                    icon: "none"
                });
            }
        });
    },
    goToDetail: function(t) {
        var e = this, a = t.currentTarget.dataset.index, n = e.data.list[a];
        wx.navigateTo({
            url: "formSettingDetail?id=" + n.id + "&name=" + n.name
        });
    },
    goToHistory: function() {
        wx.navigateTo({
            url: "history"
        });
    }
});